package com.biomatch.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.biomatch.domain.CourseOrder;
import com.biomatch.domain.Teacher;
import com.biomatch.domain.Type;
import com.biomatch.dto.Pagination;
import com.biomatch.dto.TeacherCoursePagination;
import com.biomatch.response.RestResponse;
import com.biomatch.response.RestResult;
import com.biomatch.service.CourseOrderService;
import com.biomatch.service.TeacherService;
import com.biomatch.utils.Internationalize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("dance.courseOrder")
@RequestMapping("/courseOrder")
@Api(value = "街舞课程管理")
public class CourseOrderController {
    @Autowired
    private Internationalize internationalize;

    @Autowired
    private CourseOrderService courseOrderService;

    @RequestMapping(value="/getAllByPage", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取课程信息", response = CourseOrder.class, httpMethod = "POST")
    public RestResult<CourseOrder> getAllByPage(@RequestBody Pagination pagination) {
        IPage<CourseOrder> result=courseOrderService.getAllByPage(pagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getCourseByTeacherId", method = RequestMethod.POST)
    @ApiOperation(value = "分页获取课程信息", response = CourseOrder.class, httpMethod = "POST")
    public RestResult<CourseOrder> getCourseByTeacherId(@RequestBody TeacherCoursePagination teacherCoursePagination) {
        IPage<CourseOrder> result=courseOrderService.getCourseByTeacherId(teacherCoursePagination);
        return RestResponse.success(result);
    }

    @RequestMapping(value="/getAll", method = RequestMethod.POST)
    @ApiOperation(value = "获取全部课程", response = CourseOrder.class, httpMethod = "POST")
    public RestResult<List<CourseOrder>> getAll() {
        List<CourseOrder> result =courseOrderService.getAll();
        return RestResponse.success(result);
    }

    @RequestMapping(value="/saveOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "新增或更新", response = CourseOrder.class, httpMethod = "POST")
    public RestResult<CourseOrder> saveOrUpdate(@RequestBody CourseOrder courseOrder) {
        CourseOrder result = courseOrderService.saveOrUpdate(courseOrder);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("课程名字重复"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/delete", method = RequestMethod.POST)
    @ApiOperation(value = "删除", response = CourseOrder.class, httpMethod = "POST")
    public RestResult<CourseOrder> delete(@RequestBody CourseOrder courseOrder ) {
        CourseOrder result = courseOrderService.delete(courseOrder);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("课程名称正在使用"));
        } else {
            return RestResponse.success(result);
        }
    }

    @RequestMapping(value="/deleteCourse", method = RequestMethod.POST)
    @ApiOperation(value = "删除某个老师的某个课程", response = String.class, httpMethod = "POST")
    public RestResult<CourseOrder> deleteCourse(@RequestParam(value="courseId", required = false)  String courseId ) {
        CourseOrder result = courseOrderService.deleteCourse(courseId);
        if (result == null) {
            return RestResponse.error(internationalize.getMessage("课程名称正在使用"));
        } else {
            return RestResponse.success(result);
        }
    }





}
